package com.lengxf.redis.redisTest.listener;

import com.lengxf.redis.service.listener.RedisListener;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.listener.PatternTopic;
import org.springframework.data.redis.listener.Topic;

import java.nio.charset.StandardCharsets;

/**
 * redis监听测试类
 *
 * @Author Lengxf
 */
//@Component
public class MyRedisListener2 implements RedisListener {

    @Override
    public Topic getTopic() {
        //监听所有事件 返回 操作类型
        return new PatternTopic("__keyspace@*");
    }

    @Override
    public void onMessage(Message message, byte[] pattern) {
        System.out.println("-----MyRedisListener2开始------");
        byte[] body = message.getBody();
        String string = new String(body, StandardCharsets.UTF_8);
        System.out.println(string);
        System.out.println("-----MyRedisListener2结束------");
    }

}
